import { fileURLToPath, URL } from "node:url";
import { defineConfig, loadEnv, ConfigEnv } from "vite";
import vue from "@vitejs/plugin-vue";

export default defineConfig((mode: ConfigEnv) => {
  const env = loadEnv(mode.mode, process.cwd());
  return {
    plugins: [vue()],
    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url)),
      },
    },
    base: '/lotteryAdmin',
    server: {
      host: "0.0.0.0", 
      port: env.VITE_PORT as unknown as number,
      hmr: true,
      proxy: {
        "/api": {
          target: env.VITE_API_URL,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ""),
        },
      },
    },
    build: {
      outDir: "adminDist",
      chunkSizeWarningLimit: 1500,
      rollupOptions: {
        output: {
          // entryFileNames: `assets/[name].[hash].js`,
          // chunkFileNames: `assets/[name].[hash].js`,
          // assetFileNames: `assets/[name].[hash].[ext]`,
          compact: true,
        },
      },
    },
  };
});
